﻿Public Class DateTimeStringConverter
    Implements Data.IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Dim DataHora As Date = DirectCast(value, Date)

        Return Right("00" & DataHora.Day, 2) & "/" & Right("00" & DataHora.Month, 2) & "/" & Right("00" & DataHora.Year, 2) & " " & _
               Right("00" & DataHora.Hour, 2) & ":" & Right("00" & DataHora.Minute, 2) & ":" & Right("00" & DataHora.Second, 2)
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Return CDate(value)
    End Function
End Class

Public Class TimeStringConverter
    Implements Data.IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Dim DataHora As TimeSpan = DirectCast(value, TimeSpan)

        Return Right("00" & DataHora.Hours, 2) & ":" & Right("00" & DataHora.Minutes, 2) '& ":" & Right("00" & DataHora.Seconds, 2)
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Try
            Return TimeSpan.Parse(value)
        Catch ex As Exception
            Throw New FormatException()
        End Try
    End Function
End Class

Public Class DateStringConverter
    Implements Data.IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Dim DataHora As Date = DirectCast(value, Date)

        Return Right("00" & DataHora.Day, 2) & "/" & Right("00" & DataHora.Month, 2) & "/" & Right("0000" & DataHora.Year, 4)

    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Try
            Return CDate(value)
        Catch ex As Exception
            Throw New FormatException()
        End Try
    End Function
End Class

Public Class BooleanVisibilityConverter
    Implements Data.IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If value Then
            Return Visibility.Visible
        Else
            Return Visibility.Collapsed
        End If
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        If value = Visibility.Visible Then
            Return True
        Else
            Return False
        End If
    End Function
End Class

Public Class NotBooleanVisibilityConverter
    Implements Data.IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If value Then
            Return Visibility.Collapsed
        Else
            Return Visibility.Visible
        End If
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        If value = Visibility.Visible Then
            Return False
        Else
            Return True
        End If
    End Function
End Class